<template>
  <tbody>
    <tr v-for="(item,index) in goodList" :key="index">
      <td><input type="checkbox" @click="SelectIt(index,$event.target.checked)" :checked = "item.checked"/></td>
      <!-- <td><input type="checkbox" v-model="item.checked"/></td> -->
      <td>{{item.name}}</td>
      <td>{{item.price}}</td>
      <td>
        <button @click="subtraction(index)">-</button>
        {{item.num}}
        <button @click="addEndDj(index)">+</button>
      </td>
      <td>{{item.price * item.num}}</td>
      <td><van-button type="primary" @click="del(index)">删除</van-button></td>
    </tr>
    <tr>
        <td colspan="4"  v-if="goodList.length === 0">没有数据咯~</td>
    </tr>
  </tbody>
</template>

<script>
import { mapMutations, mapState, mapGetters } from 'vuex'
export default {
  data () {
    return {
    }
  },
  // 计算属性引用
  computed: {
    ...mapState(['goodList']),
    // 计算
    ...mapGetters(['select'])
  },
  created () {
  },

  methods: {
    ...mapMutations(['addEnd', 'reduce', 'deleteObj', 'SelectIt']),
    // 减
    subtraction (index) {
      this.reduce(index)
    },
    // 加
    addEndDj (index) {
      this.addEnd(index)
    },
    // 删除
    del (index) {
      this.deleteObj(index)
    }
  }
}
</script>

<style scoped lang='less'>

</style>
